<script src="http://www.jq22.com/jquery/jquery-1.10.2.js"></script>

<link rel="stylesheet" type="text/css" href="/css/bootstrap-select.css">
<link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet">
<div class="form-group col-sm-12">
    {!! Form::submit('保存', ['class' => 'btn btn-primary']) !!}
    <a href="{!! route('goods.index') !!}" class="btn btn-default">取消</a>
</div>

<div class="form-group col-sm-12">
    <div class="page-btn page-btn-1">基础设置</div>
    <div class="page-btn page-btn-2">详情设置</div>
    <div class="page-btn page-btn-3">关联设置</div>
</div>

<div class="page1 page-back">

    <div class="form-group col-sm-6">
        {!! Form::label('sn', '货号:') !!}
        {!! Form::text('sn', null, ['class' => 'form-control']) !!}
    </div>

    <div class="form-group col-sm-6">
        {!! Form::label('title', '名称:') !!}
        {!! Form::text('title', null, ['class' => 'form-control']) !!}
    </div>

    @if(isset($goods))
        <div class="form-group col-sm-12">
            <img src="{{$goods->pic}}" alt="" style="height: 200px">
        </div>
    @endif
    <!-- Pic Field -->
    <div class="form-group col-sm-12">
        {!! Form::label('pic', '封面图片:') !!}
        {!! Form::file('pic') !!}
    </div>
    <div class="clearfix"></div>

    <!-- Abstract Field -->
    <div class="form-group col-sm-12">
        {!! Form::label('abstract', '简介:') !!}
        {!! Form::textarea('abstract', null, ['class' => 'form-control']) !!}
    </div>

    <!-- Length Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('length', '长:') !!}
        {!! Form::text('length', isset($goods)?$goods->length:0, ['class' => 'form-control']) !!}
    </div>

    <!-- Wide Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('wide', '宽:') !!}
        {!! Form::text('wide', isset($goods)?$goods->wide:0, ['class' => 'form-control']) !!}
    </div>
    <!-- Wide Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('technology', '工艺:') !!}
        @foreach($technology as $tech)
            {!! Form::checkbox('technology_str[]', $tech,isset($goods)?(strpos($goods->technology,$tech)!==false?true:false):false) !!} {{$tech}}
        @endforeach
    </div>
    <!-- Wide Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('texture', '材质:') !!}
        @foreach($texture as $textu)
            {!! Form::checkbox('texture_str[]', $textu,isset($goods)?(strpos($goods->texture,$textu)!==false?true:false):false) !!} {{$textu}}
        @endforeach
    </div>

    <!-- Category Id Field -->
    <div class="form-group col-sm-12">
        {!! Form::label('category_id', '分类:') !!}

        @foreach($cats as $cat)
            {!! Form::radio('category_id', $cat->id,isset($goods)?($cat->id==$goods->category_id?true:false):false) !!} {{$cat->parent->title}}-{{$cat->title}}
        @endforeach
    </div>

    <!-- Price Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('price', '价格:') !!}
        {!! Form::text('price', isset($goods)?$goods->price:0, ['class' => 'form-control']) !!}
    </div>

    <!-- Gram Weight Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('gram_weight', '克重:') !!}
        {!! Form::text('gram_weight', isset($goods)?$goods->gram_weight:0, ['class' => 'form-control']) !!}
    </div>

    <!-- On Sell Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('on_sell', '是否销售:') !!}
        {!! Form::select('on_sell', ['1' => '是', '0' => '否'], isset($goods)?$goods->on_sell:1, ['class' => 'form-control']) !!}
    </div>

    <div class="form-group col-sm-6">
        {!! Form::label('show_price', '是否显示价格:') !!}
        {!! Form::select('show_price', ['1' => '是', '0' => '否'], isset($goods)?$goods->show_price:1, ['class' => 'form-control']) !!}
    </div>

<!-- Read Num Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('read_num', '浏览量:') !!}
        {!! Form::text('read_num', isset($goods)?$goods->read_num:0, ['class' => 'form-control']) !!}
    </div>

    <!-- Like Num Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('like_num', '收藏数:') !!}
        {!! Form::text('like_num', isset($goods)?$goods->like_num:0, ['class' => 'form-control']) !!}
    </div>

    <!-- Sort Field -->
    <div class="form-group col-sm-6">
        {!! Form::label('sort', '排序值 (越小越前):') !!}
        {!! Form::text('sort', isset($goods)?$goods->sort:100, ['class' => 'form-control']) !!}
    </div>
</div>

<div class="page2 page-back">
    <!-- Describe Field -->
    {!! Form::label('describe', '详情描述:' ,['class'=>'ml15']) !!}
    {!! Form::textarea('describe', null, ['class' => 'describe','id' => 'describe']) !!}
</div>

<div class="page3 page-back">

    {{--<div class="form-group col-sm-12">--}}
        {{--{!! Form::button('添加可见角色', ['class' => 'add-role btn btn-primary']) !!}--}}
        {{--<div class="role-container">--}}
            {{--@if(isset($goods) && count($goods->roles)>0)--}}
                {{--@foreach($goods->roles as $role)--}}
                    {{--<div class="mt15 form-group col-sm-12 role">--}}
                        {{--<input type="hidden" name="roles[]" value="{{$role->id}}"/>{!! $role->title !!}--}}
                        {{--<button type="button" class="btn btn-danger del_role">删除</button>--}}
                    {{--</div>--}}
                {{--@endforeach--}}
            {{--@endif--}}
        {{--</div>--}}
    {{--</div>--}}

    <div class="form-group col-sm-12">
        {!! Form::button('添加标签', ['class' => 'add-label btn btn-primary']) !!}
        <div class="label-container">
            @if(isset($goods) && count($goods->labels)>0)
                @foreach($goods->labels as $label)
                    <div class="mt15 form-group col-sm-12 label_jly">
                        <input type="hidden" name="labels[]" value="{{$label->id}}"/>{!! $label->title !!}
                        <button type="button" class="btn btn-danger del_label">删除</button>
                    </div>
                @endforeach
            @endif
        </div>
    </div>

    <div class="form-group col-sm-12">
        {!! Form::button('添加色卡', ['class' => 'add-color btn btn-primary']) !!}
        <div class="color-container">
            @if(isset($goods) && count($goods->colors)>0)
                @foreach($goods->colors as $color)
                    <div class="mt15 form-group col-sm-12 color">
                        <input type="hidden" name="colors[]" value="{{$color->id}}"/>{!! $color->title !!}
                        <button type="button" class="btn btn-danger del_color">删除</button>
                    </div>
                @endforeach
            @endif
        </div>
    </div>

    <div class="form-group col-sm-12">
        {!! Form::button('添加轮播图', ['class' => 'add-slide-show btn btn-primary']) !!}
        <div class="slide-show-container">
            @if(isset($goods) && count($goods->slideshows)>0)
                @foreach($goods->slideshows as $slideshow)
                  <span class="slide-show">
                    <img src="{!! $slideshow->pic !!}" alt="" style="height: 200px;display: inline">
                    <button type="button" class="btn btn-danger del_slide_show" onclick="delslideshow({!! $slideshow->id !!})" style="margin-top: 250px;margin-left: -55px;">删除</button>
                  </span>
                @endforeach
            @endif
        </div>
    </div>
    <div class="form-group col-sm-12">
        {!! Form::button('添加相关资料', ['class' => 'add-article btn btn-primary']) !!}
        <div class="article-container">
            @if(isset($goods) && count($goods->articles)>0)
                @foreach($goods->articles as $article)
                    <div class="mt15 form-group col-sm-12 article">
                        <input type="hidden" name="articles[]" value="{{$article->id}}"/>{!! $article->title !!}
                        <button type="button" class="btn btn-danger del_article">删除</button>
                    </div>
                @endforeach
            @endif
        </div>
    </div>
    <div class="form-group col-sm-12">
        {!! Form::button('添加相关产品', ['class' => 'add-product btn btn-primary']) !!}
        <div class="product-container">
            @if(isset($goods) && count($goods->products)>0)
                @foreach($goods->products as $product)
                    <div class="mt15 form-group col-sm-12 product">
                        <input type="hidden" name="products[]" value="{{$product->id}}"/>{!! $product->title !!}
                        <button type="button" class="btn btn-danger del_product">删除</button>
                    </div>
                @endforeach
            @endif
        </div>
    </div>
</div>

<!-- Submit Field -->

<style>
    #describe{
        display: block;
        width: 96%;
        height: 600px;
        padding: 0;
        margin: 10px 15px 15px;
    }
    .mt150{
        margin-top: 300px;
    }
    .mt15{
        margin-top: 15px;
    }
    .ml15{
        margin-left: 15px;
    }

    .page-btn{
        display: inline;
        width: 60px;
        height: 40px;
        background-color: wheat;
        border: 1px solid #ccc;
        border-top-color: rgb(204, 204, 204);
        border-right-color: rgb(204, 204, 204);
        border-bottom-color: rgb(204, 204, 204);
        border-left-color: rgb(204, 204, 204);
        border-radius: 4px;
        -webkit-box-shadow: inset 0 1px 1px
    }
    .page-chose{
        background-color: #00a0e9;
    }
    .ds-inline{
        display: inline;
    }
</style>
@section('scripts')
    @include('vendor.ueditor.assets')
    <script src="https://cdn.bootcss.com/bootstrap-confirmation/1.0.7/bootstrap-confirmation.js"></script>
    <script type="text/javascript" src="/js/bootstrap-select.js"></script>
    <script type="text/javascript">
    //删除图片
    function delslideshow(pic){
      var msg = "您真的确定要删除吗？\n\n请确认！";
      if (confirm(msg)==true){
        $.ajax({
          type: "POST",
          dataType: "json",
          url: "/admin/delpic" ,
          data: {'picid':pic},
          success: function (result) {
             if (result.code == 200) {
               alert(result.msg);
             }else{
               alert(result.msg);
             }
          },
          error : function() {
             alert("异常！");
          }
        });
      }else{
      return false;
      }
    }
        $(document).ready(function(){
          $('.selectpicker').selectpicker({'selectedText': 'cat'});
            var ue = UE.getEditor('describe');
            ue.ready(function() {
                ue.execCommand('serverparam', '_token', '{{ csrf_token() }}'); // 设置 CSRF token.
            });

            $(".page-btn").click(function(){
                $('.page-btn').removeClass('page-chose');
                $(this).addClass('page-chose');
            });

            $('.page-btn-1').click(function(){
                $('.page-back').hide();
                $('.page1').show();
            });
            $('.page-btn-2').click(function(){
                $('.page-back').hide();
                $('.page2').show();
            });
            $('.page-btn-3').click(function(){
                $('.page-back').hide();
                $('.page3').show();
            });
            <?php
                $label_str = '';
                // $label_str .= '<option value="">选择标签</option>';
                foreach ($labels as $label){
                    $label_str .= '<option value="'.$label->id.'">'.$label->title.'</option>';
                }
                $article_str = '';
                // $article_str .= '<option value="">选择文章</option>';
                foreach ($articles as $article){
                    $article_str .= '<option value="'.$article->id.'">'.$article->title.'</option>';
                }
                $goods_str = '';
                // $goods_str .= '<option value="">选择商品</option>';
                foreach ($goods_all as $goods){
                    $goods_str .= '<option value="'.$goods->id.'">'.$goods->sn.'-'.$goods->title.'</option>';
                }
                $color_str = '';
                // $color_str .= '<option value="">选择色卡</option>';
                foreach ($colors as $color){
                    $color_str .= '<option value="'.$color->id.'">'.$color->title.'</option>';
                }
                $role_str = '';
                $role_str .= '<option value="">选择可见角色</option>';
                foreach ($roles as $role){
                    $role_str .= '<option value="'.$role->id.'">'.$role->title.'</option>';
                }
            ?>
            var slide_show ='<div class="mt15 form-group col-sm-12 slide-show"><input name="slide_shows[]" style="display: inline" type="file"> <button type="button" class="btn btn-danger del_slide_show">删除</button></div>';
            var article ='<div class="mt15 form-group col-sm-12 article"><select name="articles[]" class="selectpicker bla bla bli" multiple data-live-search="true">{!! $article_str !!}</select> <button type="button" class="btn btn-danger del_article">删除</button></div>';
            var product ='<div class="mt15 form-group col-sm-12 product"><select name="products[]" class="selectpicker bla bla bli" multiple data-live-search="true">{!! $goods_str !!}</select> <button type="button" class="btn btn-danger del_product">删除</button></div>';
            var color ='<div class="mt15 form-group col-sm-12 color"><select name="colors[]" class="selectpicker bla bla bli" multiple data-live-search="true">{!! $color_str !!}</select> <button type="button" class="btn btn-danger del_color">删除</button></div>';
            var label ='<div class="mt15 form-group col-sm-12 label_jly"><select name="labels[]" class="selectpicker bla bla bli" multiple data-live-search="true">{!! $label_str !!}</select> <button type="button" class="btn btn-danger del_label">删除</button></div>';
            var role ='<div class="mt15 form-group col-sm-12 role"><select name="roles[]">{!! $role_str !!}</select> <button type="button" class="btn btn-danger del_role">删除</button></div>';

            $('.add-slide-show').click(function () {
                $('.slide-show-container').append(slide_show);
            });
            $('.add-article').click(function () {
                $('.article-container').append(article);
                $('.selectpicker').selectpicker('refresh');
            });

            $('.add-product').click(function () {
                $('.product-container').append(product);
                $('.selectpicker').selectpicker('refresh');
            });

            $('.add-color').click(function () {
                $('.color-container').append(color);
                $('.selectpicker').selectpicker('refresh');
            });
            $('.add-label').click(function () {
                $('.label-container').append(label);
                $('.selectpicker').selectpicker('refresh');
            });
            $('.add-role').click(function () {
                $('.role-container').append(role);
            });

            $('div').delegate('.del_slide_show', 'click',function () {
                this.closest('.slide-show').remove();
            });
            $('div').delegate('.del_article', 'click',function () {
                this.closest('.article').remove();
            });
            $('div').delegate('.del_product', 'click',function () {
                this.closest('.product').remove();
            });
            $('div').delegate('.del_color', 'click',function () {
                this.closest('.color').remove();
            });
            $('div').delegate('.del_label', 'click',function () {
                this.closest('.label_jly').remove();
            });
            $('div').delegate('.del_role', 'click',function () {
                this.closest('.role').remove();
            });


            //初始化
            $('.page-back').hide();
            $('.page1').show();
            $('.page-btn-1').addClass('page-chose');
        });
    </script>
@endsection
